home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9151 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Input into array of strings?
  5. Date: 8 Mar 1996 14:56:26 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4hphqq$ehd@sparcserver.lrz-muenchen.de>
  9. References: <4hnv1e$o7n@rhea.glo.be>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. sclaeys@glo.be (Sven Claeys) writes:
  13.  
  14. >Hi,
  15.  
  16. >I've got a some kind of problem reading into arrays of strings. I'm a
  17. >bit rusty in C or C++, it's been a while, so please be patient with
  18. >me.
  19.  
  20. >here we go:
  21.  
  22. >i've got a structure
  23.  
  24. >struct ImmoData
  25. >{
  26. >   char code[3][5];
  27.  
  28. "code" is an array of 3 arrays of 5 characters.
  29.  
  30. >   ....
  31. >}....;
  32.  
  33. >now i want to read data from a file with fgets(...) into this array.
  34.  
  35. >I've tried
  36. >   for (i=0; i<5; i++)
  37. >       fgets(code[i],....);
  38.  
  39. code[i] is an array of 5 characters, and accessing the 4th and the 5th
  40. element of an array of 3 (arrays of 5 characters) is very unwise.
  41.  
  42. >or
  43. >   for (i=0; i<5; i++)
  44. >       fgets((char*) code[i], ...);
  45.  
  46. code[i] is an array of 5 characters, and decays to a pointer to char
  47. in an expression context without further help. The cast does not do
  48. anything.
  49.  
  50. Kurt
  51. --
  52. | Kurt Watzka                             Phone : +49-89-2180-6254
  53. | watzka@stat.uni-muenchen.de
  54. | ua302aa@sunmail.lrz-muenchen.de
  55.